package com.oraking.android.hybridapp.dev.korealaw.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import android.content.res.AssetManager;

import com.oraking.android.hybridapp.dev.korealaw.vo.KoreaLawVO;

public class CmmStrUtil {
	
	public static StringBuffer characters(char ch[], int start, int length) {
		StringBuffer sb = new StringBuffer();
		for (int i = start; i < start + length; i++) {
			switch (ch[i]) {
			case '\r':
				break;
			case '\t':
				break;
			case '\n':
				break;
			default:
				sb.append(ch[i]);
				break;
			}
		}
		return sb;
	}

	public static String Nvl(String src, String pre) {
		if (src != null) {
			return src;
		} else {
			return pre;
		}
	}
	
	public static String getAssetsFileContent(String fileName, AssetManager am){
		StringBuffer sb = new StringBuffer();
	
		try {
			InputStream is = am.open(fileName);
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String tmp;
			while((tmp=br.readLine())!=null){
				sb.append(tmp+"\n");
			}
		} catch (IOException e) {
			//Log.d(CmmStr.ERROR, "StrUtil getAssetsFileContent Error");
		}
		
		
		
		return sb.toString();
	}
	
	public static String getListHtmlContent(ArrayList<KoreaLawVO> list){
		StringBuffer sb = new StringBuffer();
		
		for(KoreaLawVO vo : list){
			sb.append(String.format(CmmStr.HTML_LIST_LIST_TAG, vo.lawUrl, vo.lawNm, vo.lawTypeNm+" 제"+vo.lawNo+"호"));
		}
		
		return sb.toString();
	}
	
	public static String getHtmlEnd(){
		StringBuffer sb = new StringBuffer();
		
		sb.append(CmmStr.HTML_END_TAG);
		
		return sb.toString();
	}
	
	public static String getHtmlStartWithCSS(String[] files){
		StringBuffer sb = new StringBuffer();
		
		sb.append(CmmStr.HTML_START_TAG);
		
		for(String file : files){
			sb.append(String.format(CmmStr.CSS_TAG, CmmStr.CONTENT_CSS_PATH+file));
		}
		
		return sb.toString();
	}
	
}
